﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using System.Reflection;

namespace Services
{
    internal class CalculatorBaseService : BaseService

    {
        private static CalculatorBaseService _CalculatorBaseService = null;

        public CalculatorBaseService()
        { }

        public static CalculatorBaseService GetInstance()
        {
            if (null == _CalculatorBaseService)
            {
                _CalculatorBaseService = PolicyInjection.Create<CalculatorBaseService>();
            }
            return _CalculatorBaseService;
        }

        [AspectHandler(IsDataTransformation = true)]
        public string Add(string js)
        {
            string method = MethodBase.GetCurrentMethod().Name;
            var item = Newtonsoft.Json.JsonConvert.DeserializeObject<Domain.Entities.OperModel>(js);

            item.result = item.x + item.y;
            item.Id = CommHelper.KeyNumber.CreateTablePrimaryKey_Guid();
            item.Operation = method;
            _OperationServices.SaveOperModel(item);
            return Newtonsoft.Json.JsonConvert.SerializeObject(item);
        }
    }
}